package model

import (
	"database/sql/driver"
	"encoding/json"
	"gorm.io/gorm"
	"time"
)

type GormList []string

func (l GormList) Value() (driver.Value, error) {
	return json.Marshal(l)
}

func (l *GormList) Scan(Value interface{}) error {
	bytes := Value.([]byte)
	if len(bytes) > 0 {
		return json.Unmarshal(bytes, &l)
	}
	return nil
}

type BaseModel struct {
	ID        int32     `gorm:"primarykey;type:int" json:"ID"` //为什么使用int32, 就是为了兼容表字段类型
	CreatedAt time.Time `gorm:"column:add_time" json:"-"`
	UpdatedAt time.Time `gorm:"column:update_time" json:"-"`
	DeletedAt gorm.DeletedAt
	IsDeleted bool
}
